using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace UsingLib
{
    /// <summary>
    /// usage when legthy task
    /// </summary>
    public class usingCursor :IDisposable
    {
        /// <summary>
        /// the cursor to be saved / retrieved
        /// </summary>
        private Cursor m_InitialCursor;
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="theCur">initial cursor</param>
        public usingCursor(Cursor theCur)
        {

            m_InitialCursor = theCur;
            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

        }

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="theForm">form that have lengthy task</param>
        public usingCursor(Form theForm)
            : this(theForm.Cursor)
        {
        }


        #region IDisposable Members
        /// <summary>
        /// retrieve the initial cursor
        /// </summary>
        public void Dispose()
        {
            System.Windows.Forms.Cursor.Current = m_InitialCursor;
            GC.SuppressFinalize(this);
        }

        #endregion
    }
}
